const Redis = require('../utils/db/redis');
const Database = require('../utils/db/database');
module.exports = app => {
  const {
    config
  } = app;

  // 开启对应的基础
  if (config.db) {
    const dbConf = config.db;
    const types = Object.keys(dbConf);
    for (let i = 0, len = types.length; i < len; i++) {
      const item = types[i];
      const options = dbConf[item];
      if (options) {
        let db;
        if (item === 'redis') {
          db = new Redis(options);
        } else {
          db = new Database(item, options);
        }
        app[item] = db;
      }
    }
  }

};
